# cat << ►_◄ > /dev/null
#
# author : xqliang <qingliangxiong@gmail.com>
# date   : 2013 Dec 23
#
# Q: When switching from one pane to the next the pane border would merge into multiple lines and it looked very messy.
# A: Go to Preferences->Profiles->Text and change the setting of "Treat ambiguous-width characters as double-width."
# 
# @see https://jamie.curle.io/posts/tmux-displaying-split-borders-dashes-osx-lion/
# @see http://www.iterm2.com/faq.html
#
# @ref https://github.com/gpakosz/.tmux
#
# Note: To view all colors enabled
#     for i in {0..255} ; do printf "\x1b[38;5;${i}mcolour${i}\n"; done

# base
set -g default-terminal "screen-256color"
set -g display-time 3000
set -g escape-time 0
set -g history-limit 10000
set -g base-index 1
set -g pane-base-index 1

# extra prefix key (Ctrl+a)
set -g prefix2 ^a # GNU-Screen compatible prefix
bind ^a send-prefix -2

# maximize current pane
if '[[ "$(tmux -V)" < "tmux 1.8" ]]' 'bind z run "cut -c3- ~/.tmux.conf | sh -s maximize_pane"'

# split window
bind - splitw -v # vertical split (prefix -)
bind | splitw -h # horizontal split (prefix |)
bind \ splitw -h # horizontal split (prefix \)

bind q killp     # kill pane (prefix q)
bind ^q killw    # kill window (prefix Ctrl+q)
bind ^p lastp    # select the last pane (prefix Ctrl+p)
bind \; command-prompt  # command (prefix ;)

# select pane
bind k selectp -U # above (prefix k)
bind j selectp -D # below (prefix j)
bind h selectp -L # left (prefix h)
bind l selectp -R # right (prefix l)

# resize pane
bind -r ^k resizep -U 3 # upward (prefix Ctrl+k)
bind -r ^j resizep -D 3 # downward (prefix Ctrl+j)
bind -r ^h resizep -L 3 # to the left (prefix Ctrl+h)
bind -r ^l resizep -R 3 # to the right (prefix Ctrl+l)

# swap pane
bind ^u swapp -U # swap with the previous pane (prefix Ctrl+u)
bind ^d swapp -D # swap with the next pane (prefix Ctrl+d)

# reload config (prefix r)
bind r source ~/.tmux.conf \; display "Config reloaded!"

# toggle synchronization
bind ^s setw synchronize-panes

# modes
setw -g mode-keys vi
setw -g clock-mode-colour colour223
setw -g mode-attr bold
setw -g mode-fg colour223
setw -g mode-bg colour235

# pane
#set -g pane-border-bg colour232
set -g pane-border-fg colour232
#set -g pane-active-border-bg colour234
set -g pane-active-border-fg green

# statusbar
set -g status-interval 1
set -g status-keys vi

set-option -g status-bg colour235 # gray
set-option -g status-fg colour136 # yellow
set -g status-left-length 40
set -g status-left '#[fg=green](#S) #(whoami)#[default]'
set -g status-right "#[fg=cyan]%m/%d %H:%M:%S"
set -g status-justify centre

setw -g window-status-current-fg colour223
setw -g window-status-current-bg colour235
setw -g window-status-current-attr bold
setw -g window-status-format "#I:#W"
setw -g window-status-current-format "#I:#W"

# messages
set -g message-attr bold
set -g message-fg colour223
set -g message-bg colour235

# ►_◄
#
# set -e
#
# maximize_pane() {
#   # see http://tmux.svn.sourceforge.net/viewvc/tmux/trunk/examples/tmux-zoom.sh
#
#   current=$(tmux display-message -p '#W-#I-#P')
#   list=$(tmux list-window)
#
#   [[ "$current" =~ ^(.*)-([0-9]+)-([0-9]+) ]]
#   current_window=${BASH_REMATCH[1]}
#   current_pane=${BASH_REMATCH[2]}-${BASH_REMATCH[3]}
#   new_zoom_window=ZOOM-$current_pane
#
#   if [[ $current_window =~ ZOOM-([0-9]+)-([0-9+]) ]]; then
#     old_zoom_window=ZOOM-${BASH_REMATCH[1]}-${BASH_REMATCH[2]}
#     tmux select-window -t ${BASH_REMATCH[1]} \; select-pane -t ${BASH_REMATCH[2]} \; swap-pane -s $old_zoom_window.1 \; kill-window -t $old_zoom_window
#   elif [[ $list =~ $new_zoom_window ]]; then
#     tmux select-window -t $new_zoom_window
#   else
#     tmux new-window -d -n $new_zoom_window \; swap-pane -s $new_zoom_window.1 \; select-window -t $new_zoom_window
#   fi
# }
#
# $@
